package cn.bon.schedule.controller;

import cn.bon.common.bean.JsonResult;
import cn.bon.common.tool.R;
import cn.bon.schedule.api.pojo.dto.WorkOrderDTO;
import cn.bon.schedule.service.RulesWorkOrderService;
import cn.bon.schedule.api.pojo.vo.WorkOrderVO;
import cn.bon.schedule.api.pojo.po.RulesWorkOrder;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Lc_cL
 * @Date 2023/12/14
 * @Description
 */
@Tag(name = "班次管理接口")
@RestController
@RequestMapping("/work-order")
public class WorkOrderController {
    @Resource
    private RulesWorkOrderService workOrderService;

    @Operation(summary = "新增班次")
    @PostMapping()
    public JsonResult<String> add(@RequestBody WorkOrderDTO dto) {
        workOrderService.add(dto);
        return R.success("新增成功");
    }

    @Operation(summary = "分页查询班次")
    @GetMapping("/page/{current}/{pageSize}")
    public JsonResult<Page<RulesWorkOrder>> page(@PathVariable("current") int cur,
                                     @PathVariable("pageSize") int size,
                                     @RequestParam(required = false) String name,
                                     @RequestParam(required = false) String type) {

        // 填充workType
        if (cur<1) cur = 1;
        if (size<1) size = 10;

        Page<RulesWorkOrder> page = new Page<>(cur, size);
        page = workOrderService.doPage(page, name, type);
        return R.success(page);
    }

    @Operation(summary = "数据回显")
    @GetMapping("/{id}")
    public JsonResult<WorkOrderVO> getDetail(@PathVariable Long id) {

        WorkOrderVO vo= workOrderService.getDetail(id);
        return R.success(vo);
    }


    @Operation(summary = "修改班次")
    @PutMapping("/{id}")
    public JsonResult<String> edit(@PathVariable Long id,
                                   @RequestBody WorkOrderDTO dto) {
        workOrderService.edit(id,dto);
        return R.success("修改成功");
    }

    @Operation(summary = "删除班次")
    @DeleteMapping("/{id}")
    public JsonResult<String> delete(@PathVariable Long id) {
        workOrderService.detele(id);
        return R.success("删除成功");
    }




}
